package sl.com.sl;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import sl.com.sl.data.CSExchange;

public class StripesImageDialog extends JDialog {
	public StripesImageDialog(JFrame owner, CSExchange data) {
		super(owner);
		StackTraceElement[] trace = Thread.currentThread().getStackTrace();
		if (trace.length < 2) {
			SwingUtilities.invokeLater(new Runnable() {
				public void run() {
					throw new IllegalArgumentException();
				}
			});
			return;
		}

		if (!"showImageDialog".equals(Thread.currentThread().getStackTrace()[2]
				.getMethodName())) {
			SwingUtilities.invokeLater(new Runnable() {
				public void run() {
					throw new IllegalArgumentException();
				}
			});
			return;
		}

		setTitle("Generated image view");
		setDefaultCloseOperation(2);

		/*
		 * StripesImageContainer c = new
		 * StripesImageContainer(getDemoImage(data), data.getEditor());
		 * JScrollPane sp = new JScrollPane(c); getContentPane().add(sp);
		 */
		JPanel pnlButtons = new JPanel(new FlowLayout(2));
		JButton btnClose = new JButton("Close");
		btnClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				StripesImageDialog.this.dispose();
			}
		});
		pnlButtons.add(btnClose);

		getContentPane().add(pnlButtons, "South");
		pack();
	}

	public BufferedImage getDemoImage(CSExchange data) {
		return ImageCreator.createStripesImage(data);
	}
}